<?php 

//QQ登陆
function qq_login()
{
	Vendor('QQConnect.API.qqConnectAPI');
	$qc = new QC();
	$qc->qq_login();

}

//QQ登陆 回掉 返回openid
function qq_openid()
{
	Vendor('QQConnect.API.qqConnectAPI');
	$qc = new QC();
    $qc->qq_callback();
	return $qc->get_openid();
}

//获取QQ用户信息
function qq_userinfo()
{
	Vendor('QQConnect.API.qqConnectAPI');
	$qc = new QC();
	return $qc->get_user_info();
}

//对QQ头像url 处理保存到服务器 return 路径
function qq_face($url)
{
	//初始化
	$ch = curl_init();
	//设置选项，包括URL
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	//执行并获取HTML文档内容
	$output = curl_exec($ch);
	//释放curl句柄
	curl_close($ch);
	//打印获得的数据
	$path = "./Uploads/Uploads/qq/".uniqid().".jpg";

	file_put_contents($path,$output);

	return $path;
}


/**
*发邮件 使用 PHPMailer第三方类
*@param 发送$email
*@param 标题$title
*@param content
*
*/
function qq_mail($email,$title,$str)
{
	Vendor('PHPMailer.PHPMailerAutoload');

	//全局方法 获取网站邮箱信息
	$emailinfo = sys_is_email();

	$mail = new PHPMailer;

	//$mail->SMTPDebug = 3;                               // Enable verbose debug output

	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Host = $emailinfo['server_smtp'];  // Specify main and backup SMTP servers
	$mail->SMTPAuth = true;                               // Enable SMTP authentication
	$mail->Username = $emailinfo['smtp_username'];                  // SMTP username
	$mail->Password = $emailinfo['smtp_password'];                           // SMTP password
	$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
	$mail->Port = $emailinfo['email_port'];                                    // TCP port to connect to

	$mail->setFrom($emailinfo['smtp_username'], '社区管理员雄哥');
	$mail->addAddress($email, '社区管理员雄哥');                    // Add a recipient
	// $mail->addAddress('ellen@example.com');               // Name is optional
	// $mail->addReplyTo('info@example.com', 'Information');
	// $mail->addCC('cc@example.com');
	// $mail->addBCC('bcc@example.com');

	// $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
	// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
	$mail->isHTML(true);                                  // Set email format to HTML

	$mail->Subject = $title;
	$mail->Body    = $str;
	//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

	if(!$mail->send()) {
	    // echo 'Message could not be sent.';
	    // echo 'Mailer Error: ' . $mail->ErrorInfo;
	    redirect("myemail", 3, '邮件发送失败');

	} else {
	    //echo 'Message has been sent';
	    redirect("myemail", 3, '邮件发送中...');
	}

}


//中午分词  class类
function zw_pscws4($w)
{
	// 加入头文件
	// require '/path/to/pscws4.class.php';

	Vendor('Pscws4.pscws4','','.class.php');

	// 建立分词类对像, 参数为字符集, 默认为 gbk, 可在后面调用 set_charset 改变
	$pscws = new PSCWS4('utf8');

	$pscws->set_dict('./Public/dict.utf8.xdb');
	$pscws->set_rule('./ThinkPHP/Library/Vendor/Pscws4/etc/rules.ini');

	$pscws->send_text($w);

	// while ($some = $pscws->get_result())
	// {
	//    foreach ($some as $word)
	//    {
	//       //var_dump($word);
	//    }
	// }
	// return $word;

	$some = $pscws->get_result();
	//var_dump($some);
	return $some;


	//$tops = $pscws->get_tops(3,'n,v');
	//return $tops;

	// var_dump($pscws);

}

//系统数据 QQ登陆 开启状态查询
function sys_is_qq()
{
	$sql = 'select * from sys_set where id=2';
	$is_qq = M()->query($sql);
	//print_r($is_qq[0]['set_state']);
	return $is_qq[0]['set_state'];

}

//网站发送邮箱信息查询
function sys_is_email()
{
	$sql = 'select * from sys_set where id=3';
	$emailinfo =  M()->query($sql);
	$emailinfo = current($emailinfo);
	return $emailinfo;
}

//前台网站禁止访问检测
function site_on_off()
{
    $sql = 'select * from sys_set where id=1';
    $site_on_offinfo = M()->query($sql);
    return $site_on_offinfo[0]['set_state'];
    
}


 ?>